#ifndef EDITORINTERFACE_H
#define EDITORINTERFACE_H
#include <QtGui>
#include "includes.h"
#include "glwindow.h"
#include "rendermanager.h"
#include "editorlogic.h"
#include "vlmodebar.h"
#include "vltoolbar.h"
#include <string>
#include "vlbrushcontextwidget.h"
#include "vlerasercontextwidget.h"
#include "vlselectorcontextwidget.h"
#include "vlfillcontextwidget.h"
#include "vltransformcontextwidget.h"
#include "vlpropertieswidget.h"
#include "vlmagicwandcontextwidget.h"
#include "vlgameelementscontextwidget.h"
#include "vlterraincontextwidget.h"

using namespace std;

class EditorInterface : public QMainWindow
{
    Q_OBJECT
public:
    EditorInterface(EditorLogic *controller);
    RenderManager* getRenderManager();

private slots:
    // utility functions
    void quit();
    void load();
    void save();

    // tool selector
    void brushToolSelected();
    void selectToolSelected();
    void eraserToolSelected();
    void fillToolSelected();
    void transformToolSelected();
    void magicWandToolSelected();
    void gameElementsToolSelected();
    void terrainToolSelected();
    void colorToolSelected();

    // brush context
    void brushShapeChanged(int);
    void brushSizeChanged(int);
    void brushHeightChanged(int);
    void brushBreadthChanged(int);
    void addBrushShape(QString name, int index);
    void delBrushShape(int index);

    // eraser context
    void eraserShapeChanged(int);
    void eraserSizeChanged(int);
    void eraserHeightChanged(int);
    void eraserBreadthChanged(int);

    // game elements context
    void setDoorFaceSide(int index);
    void setEnemySpeed(int val);
    void setEnemyWidth(int val);
    void setEnemyDepth(int val);
    void setSpikesDamage(int val);
    void setLadderOrientation(int index);

    // procedural terrain tool
    void generateTerrain(QString,QString,QString,QString,int,int,int,int,int,int);

    // color tool
    void colorValueChanged(QColor);

    // mode selector
    void selectMode(const QString &mode);

    void hideToolBar();
    void showToolBar();

signals:
    void gameModeSelected();
    void createModeSelected();
    void updateStatusBar( const QString & );

protected:
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void keyPressEvent(QKeyEvent *event);
    void keyReleaseEvent(QKeyEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    void enterEvent(QEvent *event);
    void leaveEvent(QEvent *event);

private:
    EditorLogic *controller;
//    GlobalStates *global;

    // FILE MENU actions
    QAction *loadAction;
    QAction *quitAction;
    QAction *saveAction;

    // MENU/TOOLBAR widgets
    QMenu *fileMenu;
    VLModeBar *modeBar;
    VLToolBar *tools;

    // CONTEXT BAR
    QToolBar *contextBar;
    QAction *currentCtxAxn;

    VLBrushContextWidget *brushCtx;
    QAction *brushCtxAxn;

    VLEraserContextWidget *eraserCtx;
    QAction *eraserCtxAxn;

    VLSelectorContextWidget *selectorCtx;
    QAction *selectorCtxAxn;

    VLFillContextWidget *fillCtx;
    QAction *fillCtxAxn;

    VLTransformContextWidget *transformCtx;
    QAction *transformCtxAxn;

    VLMagicWandContextWidget *magicWandCtx;
    QAction *magicWandCtxAxn;

    VLGameElementsContextWidget *gameElementsCtx;
    QAction *gameElementsCtxAxn;

    VLTerrainContextWidget *terrainCtx;
    QAction *terrainCtxAxn;

    QColorDialog *colorDialog;

    VLPropertiesWidget *properties;
    QDockWidget *propertiesDock;

    // central widget
    GLWindow *glwindowWidget;

    //status bar
    QStatusBar *status;
    QLabel * errorLabel;

    void setupMenus();
    void setupFileMenu();
    void setupCentralWidget();
    void setupWindow();
    void setupToolBar();
    void setupModeBar();
    void setupContextBar();
    void setupPropertiesWidget();
    void setupStatusBar();
    void setupDefaults();

    void setCurrentVisibleContext(QAction *ctxAxn);
    void showCurrentVisibleContext(bool visible);
    QAction * addAndHideContext(VLContextWidget *ctx);
    QString resultToString(Result r);
};

#endif // EDITORINTERFACE_H
